package com.snowy.hidden.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2WebMvc
public class Swagger2Config {

	private static final String BASE_PACKAGE = "com.snowy";
	@Value("${knife4j.enable}")
	private boolean swaggerShow;
	@Value("${knife4j.version}")
	private String version;

	@Bean(value = "createRestApi1")
	public Docket createRestApi1() {
		return new Docket(DocumentationType.SWAGGER_2).enable(true).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE))
				.paths(PathSelectors.any()).build().groupName("A");
	}

	@Bean
	public Docket createRestApi() {
		List<Parameter> pars = new ArrayList<Parameter>();

		return new Docket(DocumentationType.SWAGGER_2)
				.enable(swaggerShow)
				.apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE)).paths(PathSelectors.any()).build()
				.globalOperationParameters(pars).apiInfo(apiInfo());
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("demoAPI")
				.description("...")
				.termsOfServiceUrl("")
				.version(version)
				.build();
	}

}
